<template>
	<view class="tianjia_ka">
		<view class="list">
			<view class="info_list" @tap="showPicker('region')">
				<view class="info">收货地址</view>
				<view class="input" readonly type="text" value="" placeholder="请选择收货地址" placeholder-style="color:#a5a5a5;">{{address}}</view>
			</view>
			<view class="info_list">
				<view class="info">详细地址</view>
				<input class="input" type="text" value="" v-model="xxaddress" placeholder="请填写详细地址" placeholder-style="color:#a5a5a5;"/>
			</view>
			<view class="info_list">
				<view class="info">联系人</view>
				<input class="input" type="text" value="" v-model="name" placeholder="请填写联系人" placeholder-style="color:#a5a5a5;"/>
			</view>
			<view class="info_list">
				<view class="info">手机号</view>
				<input class="input" type="text" value="" v-model="phone" placeholder="请填写手机号" placeholder-style="color:#a5a5a5;"/>
			</view>
			<view class="info_list">
				<view class="list">
					<radio-group class="list_con"  @change="radioChange">
						<view class="info1">
							<label class="right1">
								<view class="l_radio">
									<radio value="0" :checked="sex==1"  color="#284179" style="transform:scale(0.8)"/>
								</view>
							</label>
							<view class="left">
								<view>先生</view>
							</view>
						</view>
						<view class="info1">
							<label class="right1">
								<view class="l_radio">
									<radio value="1" :checked="sex==2"  color="#284179" style="transform:scale(0.8)"/>
								</view>
							</label>
							<view class="left">
								<view>女士</view>
							</view>
						</view>
					</radio-group>
				</view>
			</view>
			<w-picker mode="region" @confirm="onConfirm($event,'region')" ref="region"></w-picker>
		</view>
		<view class="qd_btn" @click="sub">保存</view>
	</view>
</template>

<script>
	import wPicker from '@/components/w-picker/w-picker.vue';
	export default {
		components:{
			wPicker
		},
		data() {
			return {
				address:"",//收货地址
				xxaddress:"点击选择",//详细地址
				name:'',//收货人
				phone:'',//手机号
				sex:0,//性别
				id:0,
				city:'',
				province:'',
				area:'',
				provinceCode:'',
				cityCode:'',
				areaCode:''
			}
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
			    title: '修改地址'
			});
			
			this.id=options.id;
			this.getinfo();
		},
		methods: {
			showPicker(type) {
				this.$refs[type].show();
			},
			onConfirm(res, type) {
				switch (type) {
					case "region":
						this.address = res.result;
						this.provinceCode = res.value[0];
						this.cityCode = res.value[1];
						this.areaCode = res.value[2];
						this.province = res.obj.province.label;
						this.city = res.obj.city.label;
						this.area = res.obj.area.label;
						break;
				}
				console.log(this.sheng);
			},
			getinfo(){
				var that=this;
				console.log(that.userinfo);
				this.$http.get('user/editAddress',{'id':that.id}).
				then(function (response) {
					var data=response.data;
					that.address=data.address;
					that.xxaddress=data.addressDetail;
					that.name=data.name;
					that.phone=data.phone;
					that.sex=data.sex;
				}).catch(function (error) {
					console.log(error);
				});
				
			},
			radioChange(evt){
				this.sex = parseInt(evt.detail.value)+1;
			},
			sub(){
				if(this.address==''||this.address==undefined||this.address==null){
					uni.showToast({
						icon:'none',
						title:'请填写地址'
					})
					return;
				}
				if(this.xxaddress==''||this.xxaddress==undefined||this.xxaddress==null){
					uni.showToast({
						icon:'none',
						title:'请填写详细地址'
					})
					return;
				}
				
				if(this.name==''||this.name==undefined||this.name==null){
					uni.showToast({
						icon:'none',
						title:'请填写收货人'
					})
					return;
				}
				if(this.phone==''||this.phone==undefined||this.phone==null){
					uni.showToast({
						icon:'none',
						title:'请填写手机号'
					})
					return;
				}
				if(this.sex==0){
					uni.showToast({
						icon:'none',
						title:'请选择性别'
					})
					return;
				}
				
				var that=this;
				this.$http.post('user/editAddress',{'id':that.id,'province':that.province,'city':that.city,'area':that.area,'provinceCode':that.provinceCode,'cityCode':that.cityCode,'areaCode':that.areaCode,'xxaddress':that.xxaddress,'name':that.name,'phone':that.phone,'sex':that.sex}).
				then(function (response) {
					var clock=setInterval(function(){
						uni.showToast({
							title:"修改成功",
							icon:'none'
						})
						clearInterval(clock);
						uni.navigateBack();
					},1500);
				}).catch(function (error) {
					console.log(error);
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.tianjia_ka{
		width: 100%;
		.list{
			padding: 0 30rpx;
			.info_list1{
				padding: 30rpx 0;
				display: flex;
				// align-items: center;
				border-bottom:1px solid #e5e5e5;
				.info{
					margin-right: 20rpx;
					text-align-last: justify;
					width: 140rpx;
					color: #3b3b3b;
					font-size: 30rpx;
				}
				.list{
					margin-left: 70rpx;
					.list_con{
						display: flex;
						.info1{
							display: flex;
							align-items: center;
							padding-left: 50rpx;
							.left{
								align-items: center;
								display: flex;
								font-size: 30rpx;
								color: #3b3b3b;
							}
						}
					}
				}
				.input{
					flex: 1;
					font-size: 28rpx;
					color: #a5a5a5;
				}
				.right{
					width: 540rpx;
					color: #a5a5a5;
					font-size: 30rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.r_left{
						.name{
							color: #454545;
						}
						.r_l_img{
							width: 28rpx;
							height: 40rpx;
							margin-right: 10rpx;
						}
					}
					.s_img{
						width: 20rpx;
						height: 30rpx;
					}
				}
			}
			.info_list{
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom:1px solid #e5e5e5;
				.info{
					margin-right: 20rpx;
					text-align-last: justify;
					width: 140rpx;
					color: #3b3b3b;
					font-size: 30rpx;
				}
				.list{
					margin-left: 70rpx;
					.list_con{
						display: flex;
						.info1{
							height:100rpx;
							display: flex;
							align-items: center;
							padding-left: 50rpx;
							.left{
								height: 100rpx;
								align-items: center;
								display: flex;
								font-size: 30rpx;
								color: #3b3b3b;
							}
						}
					}
				}
				.input{
					flex: 1;
					font-size: 28rpx;
					color: #a5a5a5;
				}
				.right{
					width: 540rpx;
					color: #a5a5a5;
					font-size: 30rpx;
					display: flex;
					justify-content: space-between;
					height: 100rpx;
					align-items: center;
					.r_left{
						display: flex;
						height: 100rpx;
						align-items: center;
						.r_l_img{
							width: 28rpx;
							height: 40rpx;
							margin-right: 10rpx;
						}
					}
					.s_img{
						width: 20rpx;
						height: 30rpx;
					}
				}
			}
		}
		.qd_btn{
			margin: 200rpx auto 0;
			text-align: center;
			width: 670rpx;
			height: 90rpx;
			background: #284179;
			color: #fff;
			line-height: 90rpx;
			font-size: 36rpx;
			border-radius: 45rpx;
		}
	}
</style>
